package com.liqi.web.controller.monitor;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.liqi.common.annotation.Log;
import com.liqi.common.core.controller.BaseController;
import com.liqi.common.core.domain.AjaxResult;
import com.liqi.common.core.page.TableDataInfo;
import com.liqi.common.enums.BusinessType;
import com.liqi.common.utils.poi.ExcelUtil;
import com.liqi.deployment.domain.DvDeploymentModule;
import com.liqi.deployment.service.IDvDeploymentModuleService;
import com.liqi.device.domain.DvModule;
import com.liqi.monitor.domain.DvDeploymentPatrol;
import com.liqi.monitor.domain.DvDeploymentSystem;
import com.liqi.monitor.service.IDvDeploymentPatrolService;
import com.liqi.monitor.service.IDvDeploymentSystemService;

/**
 * 设备部署巡检Controller
 * 
 * @author fucx
 * @date 2022-10-24
 */
@RestController
@RequestMapping("/deployment/patrol")
public class DvDeploymentPatrolController extends BaseController
{  
	@Autowired
    private IDvDeploymentSystemService dvDeploymentSystemService;
    @Autowired
    private IDvDeploymentPatrolService dvDeploymentPatrolService;
    @Autowired
    private IDvDeploymentModuleService DvDeploymentModuleService;

    /**
     * 查询设备部署巡检列表
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:list')")
    @GetMapping("/list")
    public TableDataInfo list(DvDeploymentPatrol dvDeploymentPatrol)
    {
        startPage();
        List<DvDeploymentPatrol> list = dvDeploymentPatrolService.selectDvDeploymentPatrolList(dvDeploymentPatrol);
        return getDataTable(list);
    }
    /**
     * 根据deviceId查询设备运行状态
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:list')")
    @GetMapping("/systemlist")
    public TableDataInfo listSystem(DvDeploymentPatrol dvDeploymentPatrol)
    {
        startPage();
        DvDeploymentSystem dvDeploymentSystem = new DvDeploymentSystem();
        dvDeploymentSystem.setDeviceId(dvDeploymentPatrol.getDeviceId());
        List<DvDeploymentSystem> list = dvDeploymentSystemService.selectDvDeploymentSystemList(dvDeploymentSystem);
        return getDataTable(list);
    }
    /**
     * 根据deviceId查询设备模块详情
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:list')")
    @GetMapping("/modulelist")
    public TableDataInfo listModule(DvDeploymentPatrol dvDeploymentPatrol)
    {
        startPage();
        DvDeploymentModule dvModule = new DvDeploymentModule();
        dvModule.setDeviceId(dvDeploymentPatrol.getDeviceId());
        List<DvDeploymentModule> list = DvDeploymentModuleService.selectDvDeploymentModuleList(dvModule);
        return getDataTable(list);   
    }
    /**
     * 导出设备部署巡检列表
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:export')")
    @Log(title = "设备部署巡检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DvDeploymentPatrol dvDeploymentPatrol)
    {
        List<DvDeploymentPatrol> list = dvDeploymentPatrolService.selectDvDeploymentPatrolList(dvDeploymentPatrol);
        ExcelUtil<DvDeploymentPatrol> util = new ExcelUtil<DvDeploymentPatrol>(DvDeploymentPatrol.class);
        util.exportExcel(response, list, "设备部署巡检数据");
    }

    /**
     * 获取设备部署巡检详细信息
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dvDeploymentPatrolService.selectDvDeploymentPatrolById(id));
    }

    /**
     * 新增设备部署巡检
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:add')")
    @Log(title = "设备部署巡检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DvDeploymentPatrol dvDeploymentPatrol)
    {
        return toAjax(dvDeploymentPatrolService.insertDvDeploymentPatrol(dvDeploymentPatrol));
    }

    /**
     * 修改设备部署巡检
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:edit')")
    @Log(title = "设备部署巡检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DvDeploymentPatrol dvDeploymentPatrol)
    {
        return toAjax(dvDeploymentPatrolService.updateDvDeploymentPatrol(dvDeploymentPatrol));
    }

    /**
     * 删除设备部署巡检
     */
    @PreAuthorize("@ss.hasPermi('deployment:patrol:remove')")
    @Log(title = "设备部署巡检", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dvDeploymentPatrolService.deleteDvDeploymentPatrolByIds(ids));
    }
}
